//
// Description: 898. 数字三角形
// Created by Loading on 2022/6/2.
//

#include <bits/stdc++.h>

using namespace std;

constexpr int N = 510, INF = 1e9;

int a[N][N];
// dp[i][j] 表示第 i 行第 j 列位置结尾，路径和最大值
int dp[N][N];

int main() {
    int n;
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= i; ++j) {
            cin >> a[i][j];
        }
    }

    // 初始化dp数组
    for (int i = 0; i <= n; ++i) {
        for (int j = 0; j <= i + 1; ++j) {
            dp[i][j] = -INF;
        }
    }
    dp[1][1] = a[1][1];

    for (int i = 2; i <= n; ++i) {
        for (int j = 1; j <= i; ++j) {
            // 由左上角或右上角转移而来
            dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - 1]) + a[i][j];
        }
    }

    cout << *max_element(dp[n], dp[n] + n) << endl;

    return 0;
}